<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/Sys/css/layui.css">
    <link rel="stylesheet" href="/Sys/css/sign.css">


    <link rel="stylesheet"
          href="/Sys/js/css/modules/layui-icon-extend/iconfont.css">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/Sys/css/font.css">
    <link rel="stylesheet" href="/Sys/css/xadmin.css">


    <script type="text/javascript"
            src="/Sys/js/jquery-3.3.1.min.js"></script>
    <script src="/Sys/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script type="text/javascript" src="/Sys/js/jquery.table2excel.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">

    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">


        <!--        <div class="demoTable" style="margin-bottom: 20px">-->
        <!--            搜索姓名s：-->
        <!--            <div class="layui-inline">-->
        <!--                <input class="layui-input" name="id" id="demoReload" autocomplete="off">-->
        <!--            </div>-->
        <!--            <button class="layui-btn" data-type="reload"><i class="layui-icon">&#xe615;</i></button>-->
        <!--        </div>-->


    </div>

    <xblock>
        <!--        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>-->
        <!--        <button class="layui-btn" onclick="stuAdd()"><i class="layui-icon"></i>添加</button>-->
    </xblock>
    <table id="test" lay-filter="test"></table>

</div>
</body>

<script type="text/html" id="barDemo">
    <a title="下载简历" class="layui-btn layui-btn-xs" lay-event="dow" href="javascript:;">
        <i class="layui-icon">&#xe63c;</i>
    </a>
    <a title="通过" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="approve" href="javascript:;">
        <i class="layui-icon">&#xe605;</i>
    </a>
    <a title="驳回" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="reject" href="javascript:;">
        <i class="layui-icon">&#x1006;</i>
    </a>
</script>


<script>
    var documentWidth = $(document).width();
    layui.use('table', function () {
        var table = layui.table;
        table.render({
            elem: '#test'  //绑定table表格
            , id: 'jobListTable'
            , method: 'get'
            , url: '/Sys/getStudentJobs' //后台springmvc接收路径

            ,where: {status: 0}
            , page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                , groups: 1 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
                , limit: 5
                , limits: [5, 10, 15]
            }
            , cols: [
                [
                    {field: 'name', title: '名称', width: documentWidth * 10 / 100}
                    , {field: 'phone', title: '电话', width: documentWidth * 12 / 100}
                    , {field: 'salary', title: '薪酬', width: documentWidth * 8 / 100}
                    , {field: 'departmentName', title: '科室名称', width: documentWidth * 8 / 100}
                    , {field: 'location', title: '岗位地点', width: documentWidth * 8 / 100}
                    , {field: 'workingHours', title: '时间段（工作日）', width: documentWidth * 15 / 100}
                    ,
                    {
                        field: 'operation',
                        title: '操作',
                        toolbar: '#barDemo',
                        width: documentWidth * 15 / 100,
                        fixed: 'right'
                    }
                ]
            ]
        });

        //监听工具条
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'dow') {
                // 下载简历 - 直接使用文件URL
                if (data.resume) {

                    window.open('/Sys/uploads/' + data.resume);
                } else {
                    layer.msg('没有可下载的简历文件');
                }
            } else if (obj.event === 'approve') {
                // 通过申请
                layer.confirm('确定通过该申请吗？', function(index){
                    $.ajax({
                        url: '/Sys/updateStudentJobStatus',
                        type: 'POST',
                        contentType: 'application/json',
                        data: JSON.stringify({
                            userId: data.userId,
                            jobPositionId: data.jobPositionId,
                            status: 1  // 1表示通过
                        }),
                        success: function(res){
                            if(res === 'success'){
                                layer.msg('已通过申请');
                                obj.del();  // 删除行
                            } else {
                                layer.msg('操作失败，请重试');
                            }
                        }
                    });
                    layer.close(index);
                });
            } else if (obj.event === 'reject') {
                layer.confirm('确定驳回申请吗？', function(index){
                    // 驳回申请
                    $.ajax({
                        url: '/Sys/updateStudentJobStatus',
                        type: 'POST',
                        contentType: 'application/json',
                        data: JSON.stringify({
                            userId: data.userId,
                            jobPositionId: data.jobPositionId,
                            status: -1,  // -1表示驳回
                        }),
                        success: function(res){
                            if(res === 'success'){
                                layer.msg('已驳回申请');
                                obj.del();  // 删除行
                            } else {
                                layer.msg('操作失败，请重试');
                            }
                        }
                    });
                    layer.close(index);
                });

            }
        });

        var currentUserId = '[[${session.id}]]';
        debugger
        var $ = layui.$, active = {
            reload: function () {
                var demoReload = $('#demoReload');
                table.reload('jobListTable', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        keyword: demoReload.val(),
                        user: currentUserId  // Add user ID from session
                    }
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });


    // function delAll (argument) {
    //     layui.use('table',function(){
    //         var table = layui.table
    //         var checkStatus = table.checkStatus('stuInfo');
    //         if(checkStatus.data.length==0){
    //             parent.layer.msg('请先选择要删除的数据行！', {icon: 2});
    //             return ;
    //         }
    //         var nums = "";
    //         for(var i=0;i<checkStatus.data.length;i++){
    //             nums += checkStatus.data[i].stuno+",";
    //         }
    //
    //         parent.layer.msg('删除中...', {icon: 16,shade: 0.3,time:5000});
    //
    //         $.ajax({
    //             url:'deleteUsers',
    //             data:{'nums':nums},
    //             type:'post',
    //             success:function(data){
    //                 if(data=="success"){
    //                     parent.layer.msg('删除成功！', {icon: 1,time:2000,shade:0.2});
    //                     location.reload(true);
    //                 }else{
    //                     parent.layer.msg('删除失败！', {icon: 2,time:3000,shade:0.2});
    //                 }
    //             }
    //         });
    //     });
    //
    // }


    // 查看详情
    function downLoad() {

    }

    // 通过审批
    function approveJob() {
        var table = layui.table;
        var checkStatus = table.checkStatus('jobListTable');
        var data = checkStatus.data[0];
        layer.confirm('确认通过该岗位发布申请？', function (index) {
            $.ajax({
                url: '/Sys/job/approve/' + data.id,
                type: 'POST',
                success: function (res) {
                    if (res.code === 0) {
                        layer.msg('审批通过成功', {icon: 1, time: 2000, shade: 0.2});
                        location.reload(true);
                    } else {
                        layer.msg(res.msg || '审批通过失败', {icon: 2, time: 3000, shade: 0.2});
                    }
                }
            });
            layer.close(index);
        });
    }

    // 驳回申请
    function rejectJob() {
        var table = layui.table;
        var checkStatus = table.checkStatus('jobListTable');
        var data = checkStatus.data[0];
        layer.prompt({
            formType: 2,
            title: '请输入驳回原因',
            area: ['300px', '150px']
        }, function (value, index) {
            $.ajax({
                url: '/Sys/job/reject/' + data.id,
                type: 'POST',
                data: {
                    rejectReason: value
                },
                success: function (res) {
                    if (res.code === 0) {
                        layer.msg('驳回成功', {icon: 1, time: 2000, shade: 0.2});
                        location.reload(true);
                    } else {
                        layer.msg(res.msg || '驳回失败', {icon: 2, time: 3000, shade: 0.2});
                    }
                }
            });
            layer.close(index);
        });
    }

    // 格式化日期时间
    function formatDateTime(timestamp) {
        if (!timestamp) return '';
        var date = new Date(timestamp);
        var year = date.getFullYear();
        var month = (date.getMonth() + 1).toString().padStart(2, '0');
        var day = date.getDate().toString().padStart(2, '0');
        var hours = date.getHours().toString().padStart(2, '0');
        var minutes = date.getMinutes().toString().padStart(2, '0');
        return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes;
    }

    function screen() {
        //获取当前窗口的宽度
        var width = $(window).width();
        if (width > 1200) {
            return 3;   //大屏幕
        } else if (width > 992) {
            return 2;   //中屏幕
        } else if (width > 768) {
            return 1;   //小屏幕
        } else {
            return 0;   //超小屏幕
        }
    }


    function exportTable() {
        location.href = "/Sys/export";
    }


    layui.use(['form', 'layer', 'table', 'upload'], function () {
        var table = layui.table
            , form = layui.form, upload = layui.upload;
        var uploadInst = upload.render({
            elem: '#uploadExcel'
            , exts: "xls"
            , url: '/Sys/job/list' //后台springmvc接收路径
        });

    })


</script>

</html>